% !TEX TS-program = pdflatex
% !TEX encoding = UTF-8 Unicode

% This file is a template using the "beamer" package to create slides for a talk or presentation
% - Talk at a conference/colloquium.
% - Talk length is about 20min.
% - Style is ornate.

% MODIFIED by Jonathan Kew, 2008-07-06
% The header comments and encoding in this file were modified for inclusion with TeXworks.
% The content is otherwise unchanged from the original distributed with the beamer package.

\documentclass{beamer}


% Copyright 2004 by Till Tantau <tantau@users.sourceforge.net>.
%
% In principle, this file can be redistributed and/or modified under
% the terms of the GNU Public License, version 2.
%
% However, this file is supposed to be a template to be modified
% for your own needs. For this reason, if you use this file as a
% template and not specifically distribute it as part of a another
% package/program, I grant the extra permission to freely copy and
% modify this file as you see fit and even to delete this copyright
% notice. 


\mode<presentation>
{
  \usetheme{Warsaw}
  % or ...

  \setbeamercovered{transparent}
  % or whatever (possibly just delete it)
}


\usepackage{subfigure}
\usepackage[english]{babel}
% or whatever

\usepackage[utf8]{inputenc}
% or whatever

\usepackage{times}
\usepackage[T1]{fontenc}
% Or whatever. Note that the encoding and the font should match. If T1
% does not look nice, try deleting the line with the fontenc.


\title[Sharding in MongoDB] % (optional, use only with long paper titles)
{Sharding in MongoDB}


\author[Zhilei Ren] % (optional, use only with lots of authors)
{Zhilei Ren}
% - Give the names in the same order as the appear in the paper.
% - Use the \inst{?} command only if the authors have different
%   affiliation.

% This is only inserted into the PDF information catalog. Can be left
% out. 



% If you have a file called "university-logo-filename.xxx", where xxx
% is a graphic format that can be processed by latex or pdflatex,
% resp., then you can add a logo as follows:

% \pgfdeclareimage[height=0.5cm]{university-logo}{university-logo-filename}
% \logo{\pgfuseimage{university-logo}}



% Delete this, if you do not want the table of contents to pop up at
% the beginning of each subsection:
\AtBeginSubsection[]
{
  \begin{frame}<beamer>{Outline}
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}


% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command: 

%\beamerdefaultoverlayspecification{<+->}


\begin{document}

\begin{frame}
  \titlepage
\end{frame}

\begin{frame}{Outline}
  \tableofcontents
  % You might wish to add the option [pausesections]
\end{frame}


% Structuring a talk is a difficult task and the following structure
% may not be suitable. Here are some rules that apply for this
% solution: 

% - Exactly two or three sections (other than the summary).
% - At *most* three subsections per section.
% - Talk about 30s to 2min per frame. So there should be between about
%   15 and 30 frames, all told.

% - A conference audience is likely to know very little of what you
%   are going to talk about. So *simplify*!
% - In a 20min talk, getting the main ideas across is hard
%   enough. Leave out details, even if it means being less precise than
%   you think necessary.
% - If you omit details that are vital to the proof/implementation,
%   just say so once. Everybody will be happy with that.

\section{Concept}
\begin{frame}
	\begin{block}{Purpose of Sharding}
		\begin{enumerate}
				\scriptsize
			\item Database systems with large data sets and high throughput applications can challenge the capacity of a single server. 

			\item High query rates can exhaust the CPU capacity of the server. Larger data sets exceed the storage capacity of a single machine. 

			\item Finally, working set sizes larger than the system’s RAM stress the I/O capacity of disk drives.
		\end{enumerate}
	\end{block}
\end{frame}
\begin{frame}
	\begin{figure}
		\centering
		\includegraphics[width=0.5\textwidth]{sharded-collection.png}
		\caption{Conceptual diagram}
	\end{figure}
\end{frame}
\begin{frame}
	\begin{figure}
		\centering
		\includegraphics[width=0.5\textwidth]{sharded-cluster-production-architecture.png}
		\caption{Sharding in mongodb}
	\end{figure}
\end{frame}

\begin{frame}
	\begin{figure}
		\centering
		\subfigure[Range based sharding]{
		\includegraphics[width=0.5\textwidth]{sharding-range-based.png}
		}
		\subfigure[Hash based sharding]{
		\includegraphics[width=0.5\textwidth]{sharding-hash-based.png}
		}
		\caption{Sharding in mongodb}
	\end{figure}
\end{frame}
\begin{frame}
	\begin{block}{Sharding in mongodb}
		\begin{enumerate}
				\scriptsize
			\item Shards store the data. To provide high availability and data consistency, in a production sharded cluster, each shard is a replica set. 
			\item Query Routers, or mongos instances, interface with client applications and direct operations to the appropriate shard or shards. The query router processes and targets operations to shards and then returns results to the clients. A sharded cluster can contain more than one query router to divide the client request load. A client sends requests to one query router. Most sharded clusters have many query routers.

			\item Config servers store the cluster’s metadata. This data contains a mapping of the cluster’s data set to the shards. The query router uses this metadata to target operations to specific shards. 
		\end{enumerate}
	\end{block}
\end{frame}
\section{Tutorial}

\begin{frame}
	\begin{block}{bash: Preliminary}
		\$mkdir data1 data2 config
	\end{block}
	\begin{block}{bash: Config server}
		\$mongod -\--configsvr -\--dbpath configdb -\--port 20000
	\end{block}
	\pause
	\begin{block}{bash: Sharded mongod}
		\$mongod -\--dbpath data1 -\--port 30000

		\$mongod -\--dbpath data2 -\--port 40000
	\end{block}
\end{frame}

\begin{frame}
	\begin{block}{bash: Mongos}
		\$mongos -\--configdb localhost:20000 -\--port 50000

		\#connect to mongos

		\$mongo -\--port 50000 
	\end{block}
	\pause
	\begin{block}{mongos shell: Mongos}
		mongos>sh.addShard("localhost:30000")

		mongos>sh.addShard("localhost:40000")

		mongos>sh.enableSharding("test")
		mongos>sh.shardCollection("test.bbs", \{\_id: "hashed"\})
		mongos> for(i = 0; i < 10000; i ++)\{db.bbs.insert(\{abc:i\})\}
		mongos>db.bbs.find().count()
	\end{block}
\end{frame}
\begin{frame}
	\begin{block}{mongo shell: Mongo}
		\$mongo -\--port 30000

		>db.bbs.find().count()

		\$mongo -\--port 40000

		>db.bbs.find().count()
	\end{block}
\end{frame}
\end{document}


